package com.ruoyi.project.system.score.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.score.domain.CompScore;
import com.ruoyi.project.system.score.service.ICompScoreService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 作品评分记录Controller
 * 
 * @author ruoyi
 * @date 2025-11-04
 */
@Controller
@RequestMapping("/comp/score")
public class CompScoreController extends BaseController
{
    private String prefix = "comp/score";

    @Autowired
    private ICompScoreService compScoreService;

    @RequiresPermissions("comp:score:view")
    @GetMapping()
    public String score()
    {
        return prefix + "/score";
    }

    /**
     * 查询作品评分记录列表
     */
    @RequiresPermissions("comp:score:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompScore compScore)
    {
        startPage();
        List<CompScore> list = compScoreService.selectCompScoreList(compScore);
        return getDataTable(list);
    }

    /**
     * 导出作品评分记录列表
     */
    @RequiresPermissions("comp:score:export")
    @Log(title = "作品评分记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompScore compScore)
    {
        List<CompScore> list = compScoreService.selectCompScoreList(compScore);
        ExcelUtil<CompScore> util = new ExcelUtil<CompScore>(CompScore.class);
        return util.exportExcel(list, "作品评分记录数据");
    }

    /**
     * 新增作品评分记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存作品评分记录
     */
    @RequiresPermissions("comp:score:add")
    @Log(title = "作品评分记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompScore compScore)
    {
        return toAjax(compScoreService.insertCompScore(compScore));
    }

    /**
     * 修改作品评分记录
     */
    @RequiresPermissions("comp:score:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompScore compScore = compScoreService.selectCompScoreById(id);
        mmap.put("compScore", compScore);
        return prefix + "/edit";
    }

    /**
     * 修改保存作品评分记录
     */
    @RequiresPermissions("comp:score:edit")
    @Log(title = "作品评分记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompScore compScore)
    {
        return toAjax(compScoreService.updateCompScore(compScore));
    }

    /**
     * 删除作品评分记录
     */
    @RequiresPermissions("comp:score:remove")
    @Log(title = "作品评分记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(compScoreService.deleteCompScoreByIds(ids));
    }
}
